class Solution {
public:
    string minWindow(string s, string t) 
    {
        int hash1[128] = {0};//统计t中字符出现的次数
        int kinds = 0;//统计t中字符的种类

        //统计t的种类
        for(auto& e : t)
        {
            if(hash1[e]++ == 0) 
                kinds++;
        }

        int hash2[128] = {0};//统计s中字符的出现次数 
        int count = 0;//用于统计s中字符出现的种类
        int minlen = INT_MAX;
        int retstart = -1;


        for(int left = 0,right = 0;right <s.size();right++)
        {
           char in = s[right];//进窗口
           //判断是否种类是否有效
            if(++hash2[in] == hash1[in])
                count++;
            while(kinds == count) 
            {
                if(right - left + 1 < minlen)
                {
                    minlen = right - left + 1;
                    retstart = left;
                }
                char out = s[left++];
                if(hash2[out]-- == hash1[out]) 
                    count--;
            }
        }

        if(retstart == -1)
            return "";
        else
            return s.substr(retstart,minlen);


    }
};
